angular.module('Controller')
.controller('QgyAppointDealModalCtrl',($scope,urls,$localStorage,NgTableParams,commonUtil,cryptUtil,wfAlert,commonConstant,$http, $uibModalInstance, items)->
    $scope.type=type=items.type
    $scope.data=items.data
    $scope.modalTitle=if type=='view' then '预约详情' else '预约处理'
    $scope.modalEnableList=commonConstant.enabledList()
    if($scope.data.status == 1)
        $scope.appointmentDealStatusList=[
            {value:2, name:'待看房'}
            {value:3, name:'已取消'}
        ]
    else
        $scope.appointmentDealStatusList=[
            {value:4, name:'已看房'}
        ]
    $scope.appointmentSuccessContractList=[
        {value:true,name:'是'}
        {value:false,name:'否'}
    ]
    editData=()->
        reqData={
            "providerName":$scope.data.providerName
            "providerPhone": $scope.data.providerPhone
            "providerFeedback":$scope.data.providerFeedback
            "receiverName":$scope.data.receiverName
            "receiverPhone": $scope.data.receiverPhone
            "receiverRemark":$scope.data.receiverRemark
            "dealResult": $scope.data.dealResult
            "status":$scope.data.status
            "successContract": $scope.data.successContract
            "contractNo": $scope.data.contractNo
        }
        if $scope.data.providerTime
            reqData.providerTime=moment($scope.data.providerTime).format('YYYY-MM-DD HH:mm:ss')
        $http.put("/appointment/#{$scope.data.id}",reqData)
        .success((resp)->
            if resp.code==0
                wfAlert.toastInfo($scope.modalTitle+'成功')
                $uibModalInstance.close('done')
            else
                wfAlert.toastError(resp.message)
        )
    $scope.confirm = ()->
        if type=='view'
            $uibModalInstance.dismiss('cancel')
        else
            editData()
    $scope.cancel =()->
        $uibModalInstance.dismiss('cancel')
)